<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Internet协议分析——TCP/IP协议概述 | XiaoZiYan</title><meta name="keywords" content="学习,TCP/IP概述"><meta name="author" content="XiaoZiYan"><meta name="copyright" content="XiaoZiYan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="学习Internet协议分析">
<meta property="og:type" content="article">
<meta property="og:title" content="Internet协议分析——TCP&#x2F;IP协议概述">
<meta property="og:url" content="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2020/10/15/Internet%E5%8D%8F%E8%AE%AE%E5%88%86%E6%9E%90%E2%80%94%E2%80%94TCP%E3%80%81IP%E6%A6%82%E8%BF%B0/index.html">
<meta property="og:site_name" content="XiaoZiYan">
<meta property="og:description" content="学习Internet协议分析">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://xiaoziyan.top/images/01d&refer=http___pic1.zhimg.jpg">
<meta property="article:published_time" content="2020-10-15T04:12:02.000Z">
<meta property="article:modified_time" content="2022-11-03T10:53:47.507Z">
<meta property="article:author" content="XiaoZiYan">
<meta property="article:tag" content="学习">
<meta property="article:tag" content="TCP&#x2F;IP概述">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://xiaoziyan.top/images/01d&refer=http___pic1.zhimg.jpg"><link rel="shortcut icon" href="/xiaoziyan/img/favicon.png"><link rel="canonical" href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan/2020/10/15/Internet%E5%8D%8F%E8%AE%AE%E5%88%86%E6%9E%90%E2%80%94%E2%80%94TCP%E3%80%81IP%E6%A6%82%E8%BF%B0/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/xiaoziyan/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/xiaoziyan/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: XiaoZiYan","link":"链接: ","source":"来源: XiaoZiYan","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Internet协议分析——TCP/IP协议概述',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-03 18:53:47'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="./css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/xiaoziyan/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/archives/"><div class="headline">文章</div><div class="length-num">33</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/tags/"><div class="headline">标签</div><div class="length-num">41</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/xiaoziyan/categories/"><div class="headline">分类</div><div class="length-num">39</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://xiaoziyan.top/images/01d&amp;refer=http___pic1.zhimg.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/xiaoziyan/">XiaoZiYan</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/xiaoziyan/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 多媒体</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/xiaoziyan/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/xiaoziyan/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/xiaoziyan/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Internet协议分析——TCP/IP协议概述</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-10-15T04:12:02.000Z" title="发表于 2020-10-15 12:12:02">2020-10-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-03T10:53:47.507Z" title="更新于 2022-11-03 18:53:47">2022-11-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E5%AD%A6%E4%B9%A0/">学习</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/xiaoziyan/categories/%E5%AD%A6%E4%B9%A0/Internet%E5%8D%8F%E8%AE%AE%E5%88%86%E6%9E%90/">Internet协议分析</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Internet协议分析——TCP/IP协议概述"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><div align='center' ><font size='50'><strong>TCP/IP协议概述</strong></font></div>

<h2 id="1-TCP-IP分层结构"><a href="#1-TCP-IP分层结构" class="headerlink" title="1.TCP/IP分层结构"></a>1.TCP/IP分层结构</h2><p>TCP/IP协议是一组开放式协议，可以进行任何组合间的通信，能够满足长距离互联系统的要求，同时分组交换的方式使得网络中只要存在有效路由，网络通信就是可以可靠进行的。</p>
<p>TCP/IP的开放是指对异构的系统是开放的，不同的厂家生产的不同型号的各种计算机，它们运行完全不同的操作系统，使用不同的网络硬件，TCP/IP协议族也能够允许它们互相进行通信。</p>
<p><strong>今天的TCP/IP具有下列主要的特点：</strong></p>
<ul>
<li><p>开放，免费使用，独立于计算机硬件与操作系统。</p>
</li>
<li><p>可以运行在局域网、广域网中，更适用于互联网上。</p>
</li>
<li><p>统一的网络地址分配方案</p>
</li>
<li><p>标准化的高层协议，可以提供多种可靠的用户服务。</p>
</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211125092923342.png"></p>
<ul>
<li><p><strong>数据链路层</strong>：也称作数据链路层或网络接口层，通常包括操作系统中的设备驱动程序和计算机中对应的网络接口卡。它们一起处理与电缆（或其他任何传输媒介）的物理接口细节。</p>
</li>
<li><p><strong>网络层</strong>：有时也称作互联网层，处理分组在网络中的活动，例如分组的选路。在TCP/IP协议族中，网络层协议包括IP协议（网际协议），ICMP协议（网际控制报文协议）以及IGMP协议（网际组管理协议）。</p>
</li>
<li><p><strong>传输层</strong>：主要为两台主机上的应用程序提供端到端的通信。在TCP/IP协议族中，有两个互不相同的传输协议： TCP（传输控制协议）和UDP（用户数据报协议）。</p>
</li>
<li><p><strong>应用层</strong>：负责处理特定的应用程序细节。几乎各种不同的TCP/IP实现都会提供下面这些通用的应用程序： Telnet远程登录，SMTP（简单邮件传输协议)，FTP（文件传输协议)，HTTP（超文本传输协议）等。</p>
</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211125092952727.png"></p>
<h3 id="IP地址和端口"><a href="#IP地址和端口" class="headerlink" title="IP地址和端口"></a>IP地址和端口</h3><ul>
<li><p>互联网上参与通信的每一个节点可能有不止一个网络接口，但每一个接口都有一个唯一的IP地址。</p>
</li>
<li><p>同时，每一个节点上都可能运行着多个通信进程，因此通过端口号来标识参与通信的进程。</p>
</li>
<li><p>实际上，通信的主体总是进程，在互联网上唯一地标识出通信的实体的方法就是：用IP地址来区分不同节点的不同接口，用端口号来区分同一个节点上的不同进程。</p>
</li>
</ul>
<blockquote>
<p> <strong>要注意的是</strong>：一个节点可以有多个网络接口，因此就有多个IP地址。所以IP地址标识的是接口。</p>
</blockquote>
<ul>
<li><p>IPv4采用的是32bit地址，其分类和点分十进制表示法在计算机网络基础课程里已有学习。五类IP地址的格式如图1-3所示。</p>
</li>
<li><p>按目的端主机的范围可将IP地址分为三类：</p>
<blockquote>
<p>单播地址：目的端为单个主机。<br> 广播地址：目的端为给定网络上的所有主机。<br> 多播地址：目的端为同一组内的所有主机。</p>
</blockquote>
</li>
</ul>
<p><img src="http://xiaoziyan.top/images/image-20211125093154375.png"></p>
<ul>
<li><p>TCP和UDP采用16 bit的端口号来识别应用程序。 例如TCP端口号23和UDP端口号23是不同的。</p>
</li>
<li><p>服务器一般都是通过熟知端口号来识别的，由IANA（Internet号分配机构）管理，目前为1~1023。</p>
</li>
<li><p>客户端口号又称作临时端口号，通常只是在用户运行该客户程序时才存在，通常为1024~5000。</p>
</li>
<li><p>从32768开始的端口号通常作为TCP和UDP的缺省临时端口号。</p>
<blockquote>
<p> 也有把1024~65535的端口号统称为动态端口的，即指这些端口号一般不固定分配给某个服务使用。</p>
</blockquote>
</li>
</ul>
<h2 id="2-TCP-IP通信过程"><a href="#2-TCP-IP通信过程" class="headerlink" title="2.TCP/IP通信过程"></a>2.TCP/IP通信过程</h2><p>网络通信过程中，协议栈有两个非常重要的操作：</p>
<ul>
<li>在发送数据时，<code>封装</code></li>
<li>在接收数据时，<code>分用</code></li>
</ul>
<p>把握这两点对准确理解TCP/IP协议的具体工作过程十分有帮助。</p>
<p><strong>封装</strong>：TCP/IP协议族的上层协议是通过封装来使用下层服务的。应用程序数据在发送到物理网络之前，将沿着协议族从上往下依次封装。每层协议都将在上层协议的基础上加上自己的头部信息（以太网还包括尾部信息），以实现改成的功能，这个过程就是封装。</p>
<p><img src="http://xiaoziyan.top/images/image-20211125093336863.png"></p>
<p><strong>分用</strong>：当目的主机收到一个以太网数据帧时，数据就开始从协议栈中由底向上升，同时去掉各层协议加上的报文首部。每层协议都要去检查报文首部中的协议标识，以确定接收数据的上层协议。这个过程就是分用。</p>
<p>报文首部中的协议标识，以确定接收数据的上层协议。这个过程就是分用。</p>
<p><img src="http://xiaoziyan.top/images/image-20211125093430269.png"></p>
<h2 id="3、应用编程接口"><a href="#3、应用编程接口" class="headerlink" title="3、应用编程接口"></a>3、应用编程接口</h2><p>网络协议栈的实现一般都是由操作系统来完成的，在链路层还需要借助网络接口的驱动程序（网卡驱动程序）</p>
<p><strong>程序员可以使用的编程接口有两个层次：</strong></p>
<blockquote>
<ul>
<li><p>运输层和网络层主要使用<strong>套接字编程</strong>；</p>
</li>
<li><p>链路层的访问方法有<strong>BSD</strong>（Berkeley Software Distribution，伯克利软件发行版）的<strong>BPF</strong>（Berkeley Packet Filter，分组过滤器）、Linux系统下的<strong>SOCK_PACKET</strong>接口、<strong>Libpcap</strong>函数库等，现在主要使用的是Libpcap及其Windows环境下的版本<strong>Winpcap</strong>函数库。</p>
</li>
</ul>
</blockquote>
<ul>
<li>一个<strong>套接字（Socket）</strong>描述一个通信连接的一端，两个通信程序中各自有一个套接字来描述自己的通信连接。</li>
</ul>
<p>套接字形式如下：<br>               <strong>(IP, PORT)</strong><br>其中的IP表示结点IP地址，PORT表示端口号，再加上表示通信协议的参数，一个网间通信标识为一个五元组：</p>
<p>​    <strong>&lt;协议， 本地地址，本地端口，远程地址， 远程端口&gt;</strong></p>
<ul>
<li><p>基本Socket API有若干的常用函数，包括socket()、close()、bind()、listen()、accept()、connect()、send()/recv()等 。</p>
</li>
<li><p>Socket API可以方便地实现基于TCP和UDP的编程，也可以通过原始套接字完成基于IP的编程，比如构建自己的IP数据报，因此在各种网络应用程序设计中普遍使用。</p>
</li>
<li><p>在掌握TCP/IP协议工作原理的基础上，再学习掌握Socket编程方法，就可以按照应用需要设计出不同的网络应用程序了，比如各种网络通信程序等。</p>
</li>
</ul>
<h3 id="Libpcap编程"><a href="#Libpcap编程" class="headerlink" title="Libpcap编程"></a>Libpcap编程</h3><ul>
<li><p>Libpcap（Packet Capture library）是一个提供针对网络数据包捕获系统的高层接口的开源函数库。</p>
</li>
<li><p>它是在1994年由麦克坎尼（McCanne），莱乐士（Leres）和杰科布森（Jacobson）创建的，其设计愿望是开创一个独立平台的应用程序接口（API）以此消除程序中针对不同操作系统所包含的数据包捕获代码模块。</p>
</li>
<li><p>Libpcap解决了捕获机制在不同操作系统间的移植性的问题，这有利于提高程序员开发的效率。</p>
</li>
<li><p>Libpcap应用程序接口被设计用于C或者C++语言，通过将网卡设置为混杂模式，可以捕获所有经过该网络接口的数据包。</p>
</li>
<li><p>著名的tcpdump程序就是在Libpcap的基础上开发而成的，通过Libpcap提供的接口函数来实现数据包的采集、过滤等有关的功能。</p>
</li>
<li><p>后来出现很多封装包使Libpcap也可用于其它语言，比如：Perl语言，Python语言，Java语言，C＃或者Ruby语言。Libpcap 软件包可从<a target="_blank" rel="noopener" href="http://www.tcpdump.org/">http://www.tcpdump.org/</a> 下载。</p>
</li>
<li><p>Libpcap运行于大多数类UNIX操作系统上，Windows环境下的版本叫<strong>Winpcap</strong>。</p>
</li>
<li><p>Winpcap 是基于Win32 平台的网络包截获和分析的系统，它是Libpcap的Windows版本。</p>
</li>
<li><p>Winpcap的官方网站是<a target="_blank" rel="noopener" href="http://winpcap.polito.it/%EF%BC%8C%E4%B9%9F%E5%8F%AF%E4%BB%A5%E4%BB%8Ehttp://www.winpcap.org/%E4%B8%8B%E8%BD%BD%E5%88%B0%E5%AE%83%E7%9A%84%E9%A9%B1%E5%8A%A8%E3%80%81DLL%E5%92%8C%E5%BC%80%E5%8F%91%E5%8C%85%E3%80%82">http://winpcap.polito.it/，也可以从http://www.winpcap.org/下载到它的驱动、DLL和开发包。</a></p>
</li>
<li><p><strong>Libpcap</strong>的主要功能有：数据包捕获、自定义数据包发送、流量采集与统计和规则过滤。</p>
</li>
<li><p><strong>Libpcap</strong>最普遍的用途就是用来实现网络协议分析器，也就是网络嗅探器。</p>
</li>
<li><p>另外，还可以用来实现流量分析、入侵检测系统、网络扫描工具等网络应用。</p>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">XiaoZiYan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a target="_blank" rel="noopener" href="https://baidu.com">https://baidu.com</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://xiaoziyanxiaoludan.gitee.io/xiaoziyan" target="_blank">XiaoZiYan</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/xiaoziyan/tags/%E5%AD%A6%E4%B9%A0/">学习</a><a class="post-meta__tags" href="/xiaoziyan/tags/TCP-IP%E6%A6%82%E8%BF%B0/">TCP/IP概述</a></div><div class="post_share"><div class="social-share" data-image="http://xiaoziyan.top/images/01d&amp;refer=http___pic1.zhimg.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/xiaoziyan/2020/10/16/Internet%E5%8D%8F%E8%AE%AE%E5%88%86%E6%9E%90%E2%80%94%E2%80%94%E5%8D%8F%E8%AE%AE%E5%88%86%E6%9E%90%E5%B7%A5%E5%85%B7/"><img class="prev-cover" src="http://xiaoziyan.top/images/g&amp;refer=http___pic.qcsdn.jpg" onerror="onerror=null;src='/xiaoziyan/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Internet协议分析——协议分析工具</div></div></a></div><div class="next-post pull-right"><a href="/xiaoziyan/2020/10/14/AT%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/"><img class="next-cover" src="https://gitee.com/xiaoziyanxiaoludan/anjupicture/raw/master/images/src=http___www.u.jpg" onerror="onerror=null;src='/xiaoziyan/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">AT命令详解</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/xiaoziyan/2020/10/14/AT%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/" title="AT命令详解"><img class="cover" src="https://gitee.com/xiaoziyanxiaoludan/anjupicture/raw/master/images/src=http___www.u.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-14</div><div class="title">AT命令详解</div></div></a></div><div><a href="/xiaoziyan/2019/10/14/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94ADC%E3%80%81PWM/" title="C51单片机学习——ADC/PWM"><img class="cover" src="http://xiaoziyan.top/images/f45614980b681dfbe655f12e7ba148cd.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-14</div><div class="title">C51单片机学习——ADC/PWM</div></div></a></div><div><a href="/xiaoziyan/2019/10/09/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94lcd1602%E6%B6%B2%E6%99%B6%E5%B1%8F/" title="C51单片机学习——lcd1602液晶屏"><img class="cover" src="http://xiaoziyan.top/images/3fe2d4f7f8aa0e706e4d555656cb673a.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-09</div><div class="title">C51单片机学习——lcd1602液晶屏</div></div></a></div><div><a href="/xiaoziyan/2019/10/11/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E5%A4%96%E9%83%A8%E4%B8%AD%E6%96%AD/" title="C51单片机学习——外部中断"><img class="cover" src="http://xiaoziyan.top/images/ac104f60351a347c48895f896bc64220.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-11</div><div class="title">C51单片机学习——外部中断</div></div></a></div><div><a href="/xiaoziyan/2019/10/08/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E6%8C%89%E9%94%AE%E6%8E%A7%E5%88%B6/" title="C51单片机学习——按键控制"><img class="cover" src="http://xiaoziyan.top/images/84c58abc41610ee19e1a478f91088e69.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-08</div><div class="title">C51单片机学习——按键控制</div></div></a></div><div><a href="/xiaoziyan/2019/10/06/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%AD%A6%E4%B9%A0%E2%80%94%E2%80%94%E6%B5%81%E6%B0%B4%E7%81%AF/" title="C51单片机学习——流水灯"><img class="cover" src="http://xiaoziyan.top/images/adb7f9eca04e6f962fe5f3e4a54d1d12.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-06</div><div class="title">C51单片机学习——流水灯</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-TCP-IP%E5%88%86%E5%B1%82%E7%BB%93%E6%9E%84"><span class="toc-number">1.</span> <span class="toc-text">1.TCP&#x2F;IP分层结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#IP%E5%9C%B0%E5%9D%80%E5%92%8C%E7%AB%AF%E5%8F%A3"><span class="toc-number">1.1.</span> <span class="toc-text">IP地址和端口</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-TCP-IP%E9%80%9A%E4%BF%A1%E8%BF%87%E7%A8%8B"><span class="toc-number">2.</span> <span class="toc-text">2.TCP&#x2F;IP通信过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B%E6%8E%A5%E5%8F%A3"><span class="toc-number">3.</span> <span class="toc-text">3、应用编程接口</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Libpcap%E7%BC%96%E7%A8%8B"><span class="toc-number">3.1.</span> <span class="toc-text">Libpcap编程</span></a></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By XiaoZiYan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><p><a style="margin-inline:5px"target="_blank" href="https://hexo.io/"> <img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为 Hexo" alt="HEXO"></a><a style="margin-inline:5px"target="_blank"href="https://butterfly.js.org/"> <img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用 Butterfly" alt="Butterfly"></a><a style="margin-inline:5px"target="_blank" href="https://www.jsdelivr.com/"> <img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用 Jsdelivr 为静态资源提供CDN加速" alt="Jsdelivr"></a><a style="margin-inline:5px"target="_blank" href="https://github.com/"> <img src="https://img.shields.io/badge/Source-gitee-d021d6?style=flat&logo=Gitee" title="本站项目由 Gitee 托管" alt="Gitee"></a><a style="margin-inline:5px"target="_blank"href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> <img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" alt="img" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/xiaoziyan/js/utils.js"></script><script src="/xiaoziyan/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script src="./js/sakura.js"></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img id="card-clock-loading" src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-clock/clock/images/weather/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading" class="entered loading"></div></div></div></div></div>';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><!-- hexo injector body_end end --></body></html>